package xyz.iguilty.documents.common.utils;

import org.springframework.util.ObjectUtils;

public class DictUtil {
    public String parse(Object target,String dictionary){
        if (ObjectUtils.isEmpty(target)){
            return "";
        }
        if (!ObjectUtils.isEmpty(dictionary)){
            String[] items = dictionary.split(",");
            for (String item:items){
                String[] entry = item.split("_");
                if (entry.length>1&&target.toString().equals(entry[entry.length-1])){
                    int i = item.lastIndexOf("_");
                    return item.substring(0,i);
                }
            }
        }
        return target.toString();
    }
}
